package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.Lsh金融设置Model;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by sxy on 2016/7/11
 */
public interface Lsh金融设置Repository extends JpaRepository<Lsh金融设置Model, Integer>, JpaSpecificationExecutor<Lsh金融设置Model> {

    @SuppressWarnings("JpaQlInspection")
    @Modifying
    @Query(value = "update Lsh金融设置Model m set m.是否有效 = '否', m.是否删除 = '是' where m.产品编码 = ?1", nativeQuery = true)
    int delBy产品编码(int id);
    
    
    @Query("select  max(金融编号)   from  Lsh金融设置Model  where 许可='LSH' AND 按揭类型='先享后选' ")
	List getMaxFinanceNum();

    @Modifying
    @Query("update Lsh金融设置Model u set u.是否删除='是' where u.金融编号=?1 ")
	void updIfDelStatuToYes(Integer financeNum);

    @Query("select u from Lsh金融设置Model u where u.许可=?1 and u.产品编码=?2 and u.是否删除='否'")
    Lsh金融设置Model findByPermitAndProNum(String 许可, String 产品编码);

    @Query("select count(u) from Lsh金融设置Model u where u.许可=?1 and u.产品编码=?2  and u.是否删除='否' ")
    int  getCountByPermitAndProNum(String 许可, String 产品编码);

    @Query(" select max(u.金融编号) from Lsh金融设置Model u where u.许可=?1 and u.产品编码=?2 and u.是否删除='否' ")
    Integer  getMaxIdByPermitAndProNum(String 许可, String 产品编码);

}
